/*
 * Buffer.java
 *
 * Created on Antradienis, 2006, Spalio 3, 11.59
 *
 */

package org.mif.mobp.core;
import org.mif.mobp.core.coord.*;

/** Klase suteikia interfeisa zemesniems lygiams perduoti aukshtesnems lygiams
 * 
 */
public class Buffer {
    /**Saugomos buferije koordinates*/
    protected GeographicalCoordinates c;
    
    /*kintamas signalizuoja ar yra buferije kokia nors reikshme*/
    private boolean empty = true;
    
    /** Creates a new instance of Buffer */
    public Buffer() {
    }
    
    /**Metodas ideda koordinates i buferi */
    public synchronized void put (GeographicalCoordinates gc) {
        while (!empty) {
            try {
                wait();
            }
            catch (InterruptedException e) {
                return;
                //e.printStackTrace();
            }
        }
        c = gc;
        empty = false;
        notifyAll();
    }

    /**Metodas ishima koordinates ish buferio*/
    public synchronized GeographicalCoordinates get () {
        while (empty) {
            try {
                wait();
            }
            catch (InterruptedException e) {
                return c;
                //e.printStackTrace();
            }
        }
        empty = true;
        notifyAll();
        return c;
    }
}
